package mhl.service;


import mhl.dao.DiningTableDAO;
import mhl.domain.DiningTable;

import java.util.List;

public class DiningTableService {

    //定义一个 DiningTableDAO 对象
    private DiningTableDAO diningTableDAO = new DiningTableDAO();

    //返回所有的餐桌信息
    public List<DiningTable> getDiningTables() {
        return diningTableDAO.queryMulti
                ("select id,state from diningTable", DiningTable.class);
    }

    //根据 id 查询对应的餐桌 DiningTable 对象
    public DiningTable getDiningTableById(int id) {
        return diningTableDAO.querySingle
                ("select * from diningTable where id=?", DiningTable.class, id);
    }

    //如果餐桌可以预订，调用方法，更新其状态(包括预订人的姓名和电话)
    public boolean orderDiningTable(int id, String orderName, String orderTel) {
        int update = diningTableDAO.update
                ("update diningTable set state='已预定',orderName=?,orderTel=? where id=?",
                        orderName, orderTel, id);
        return update > 0;

    }

    //需要提供一个更新 餐桌状态 的方法
    public boolean updateDiningTableState(int id, String state) {
        int update = diningTableDAO.update("update diningTable set state=? where id=?", state, id);
        return update > 0;
    }

    //提供方法，将指定的餐桌设置为空闲状态
    public boolean updateDiningTableToFree(int id, String state){
        int update = diningTableDAO.update("update diningTable set state=?,orderName='',orderTel='' where id=?", state, id);
        return update > 0;
    }

}
